package io.gitee.zhangbinhub.acp.boot.test

import io.gitee.zhangbinhub.acp.boot.exceptions.WebException
import io.gitee.zhangbinhub.acp.core.common.NetTools
import org.apache.commons.lang3.exception.ExceptionUtils
import org.junit.jupiter.api.Test
import org.springframework.http.server.PathContainer
import org.springframework.util.AntPathMatcher
import org.springframework.web.util.pattern.PathPatternParser

class TestSimple {
    @Test
    fun test() {
        println(NetTools.getMacAddressFromIp("fe80::3113:a293:fccc:b73"))
        println(NetTools.getMacAddressFromIp("172.26.64.1"))

        val antPathMatcher = AntPathMatcher()
        val expression = "/url/{id:a|b|c}"
        val urls = listOf("/url/a", "/url/b", "/url/c", "/url/d")
        println("模式表达式：$expression")
        urls.forEach {
            println("[AntPathMatcher] 路径：$it 匹配结果：${antPathMatcher.match(expression, it)}")
        }

        val pattern = PathPatternParser().parse(expression)
        urls.forEach {
            println("[PathPatternParser] 路径：$it 匹配结果：${pattern.matches(PathContainer.parsePath(it))}")
        }

        val booleanString = "true"
        println(booleanString.toBoolean())
    }

    @Test
    fun printStack() {
        try {
            throw WebException("test error!")
        } catch (e: Exception) {
            println(e)
            println(ExceptionUtils.getStackTrace(e))
        }
    }
}